/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


myApp.controller('mealReviewController',
        //['$scope'],
        function($scope, $location, viewMealDetailsService, currentlyTrendingService, $routeParams, $cookies, postMealReview, $rootScope) {
    
    $scope.isReviewMode = true;
    $rootScope.isLoginPage = true;
    var getMealSuccess = function(respData) {
        $scope.meal = respData.data;
    }
    var getMealFailure = function(errordata) {
    }
     
    viewMealDetailsService.getMeals($routeParams.mealid).then(getMealSuccess, getMealFailure);
    
    $scope.postReviews = function(){
        var postData = {
            mealId : $routeParams.mealid,
            ratings : $scope.ratings,
            reviews : $scope.reviews
        };
        
        postMealReview.postReview(postData).then(function(){
            $rootScope.showAlert("Your review has been posted.");
            //$location.path('/viewMeal/' + $routeParams.mealid);
        }, getMealFailure);
    };
    
    $scope.rate = 2;
    $scope.max = 5;
    $scope.isReadonly = false;
    $rootScope.showWelcomeMessage = false;
        $rootScope.showSearchBar = false;
    $scope.hoveringOver = function(value) {
        $scope.overStar = value;
        $scope.percent = 100 * (value / $scope.max);
    };

    $scope.ratingStates = [
    {
        stateOn: 'glyphicon-ok-sign', 
        stateOff: 'glyphicon-ok-circle'
    },

    {
        stateOn: 'glyphicon-star', 
        stateOff: 'glyphicon-star-empty'
    },

    {
        stateOn: 'glyphicon-heart', 
        stateOff: 'glyphicon-ban-circle'
    },

    {
        stateOn: 'glyphicon-heart'
    },

    {
        stateOff: 'glyphicon-off'
    }
    ];
    
});